﻿@{
    Layout = null;
    ViewBag.Title = "角色管理——公路工程建设项目造价全过程管理系统";
}
@using KingRoad.EPM.Common.Helper
<script type="text/javascript">

    var role_jqgrid_lastID = 0; //最后一次选中的行ID
    var role_edit_url = "/Permission/Role/roleEdit/"; //编辑路径

    $(document).ready(function () {

        GridGet();
        //        var height = $("#page_Permission_Role_Index").innerHeight() - $("panelBar").height();
        //        $("#RoleTable").setGridHeight(height);
        $("#Permission_Role_delete").bind("click", function () {
            return Role_Delete();
        });
    });

    function GridGet() {
        $("#RoleTable").jqGrid({
            url: "/Permission/Role/GetAllRole",
            datatype: "json",
            mtype: "post",
            colNames: ['ID', '编号', '名称', '有效', '描述'],
            colModel: [
                        { name: 'Id', index: 'Id', width: 20, align: "center", sortable: false, hidden: true },
                        { name: 'Code', index: 'Code', width: 200, align: "center", sortable: false },
                        { name: 'Realname', index: 'Realname', width: 250, align: "center", sortable: false },
                        { name: 'Enabled', index: 'Enabled', width: 250, align: "center", formatter: "checkbox", sortable: false },
                        { name: 'Description', index: 'Description', width: 350, align: "center", sortable: false }
                       ],
            loadError: function (xhr, status) {
                alertMsg.error(xhr.responseText);
            },
            loadComplete: function (xhr) {
                var ajaxbg = $("#background,#progressBar,#lui_RoleTable");
                ajaxbg.hide();
            },
            onSelectRow: Role_GetIDbyEdit,
            autowidth: true,
            shrinkToFit: true,
            multiselect: false,
            multiselectWidth: 50,
            sortable: false,
            viewrecords: true,
            sortorder: "desc",
            jsonReader: {
                repeatitems: false
            },
            rowNum: -1,
            height: 400
        }).navGrid('#pager', { edit: false, add: false, del: false, refresh: false, search: false });
    }

    //获取所有选中行的ID    1返回行ID   2返回角色ID
    function GetSelectID() {
        var Role_Jqgrid = $("#RoleTable");
        var Role_Index_Get_ListID = $("#RoleTable").jqGrid("getGridParam", "selrow");
        if (Role_Index_Get_ListID == "")
            return "";
        var Role_Index_ListID = "";
        var temp = "";
        temp = Role_Jqgrid.getCell(Role_Index_Get_ListID, "Id").toString();
        if (temp != "" && temp != "false") {
            Role_Index_ListID = temp;
        }
        return Role_Index_ListID;
    }

    //对角色执行删除操作
    function Role_Delete() {
        var Role_Grid_SelectID = GetSelectID();
        if (Role_Grid_SelectID == "") {
            alertMsg.error("至少要勾选一条记录！");
            return false;
        }
        else {
            alertMsg.confirm("您确定要删除这个角色吗？", {
                okCall: function () {
                    $.post("/Permission/Role/Delete", { "RoleArryID": Role_Grid_SelectID }, dialogAdded, "json");
                }
            });
        }
    }

    function dialogAdded(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            var Jqgrid_ListID = $("#RoleTable").jqGrid("getGridParam", "selrow").toString();
            $("#RoleTable").delRowData(Jqgrid_ListID);
            alertMsg.correct("成功删除1条记录！");
        }
        else {
            alertMsg.error("删除失败,请稍后再试！");
        }
    }

    function dialogCreated(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点       
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            alertMsg.correct(json.message);
            $("#RoleTable").trigger("reloadGrid");
        }
        else {
            alertMsg.error(json.message);
        }
        $.pdialog.closeCurrent();
        $("#background,#progressBar,#lui_RoleTable").hide();
    }

    function dialogEdited(json) {
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            alertMsg.correct(json.message);
            $("#RoleTable").trigger("reloadGrid");
        }
        else {
            alertMsg.error(json.message);
        }
        $.pdialog.closeCurrent();
        $("#background,#progressBar,#lui_RoleTable").hide();
    }

    //为修改而获取ID
    function Role_GetIDbyEdit(rowid, status) {
        if ($("#RoleTable").jqGrid("getGridParam", "selrow").toString() == "") {
            $("#role_edit").attr("href", "/Permission/Role/roleEdit/{sid_user}");
            $("#Permission_role_select").attr("href", "/Permission/Role/roleEdit/{sid_user}");
            $("#Permission_role_SelectModule").attr("href", "/Permission/Role/SelectModule/{sid_user}");
            $("#Permission_role_LinkUser").attr("href", "/Permission/Role/LinkUser/{sid_user}");
            $("#Permission_role_SelectPermission").attr("href", "/Permission/Role/SelectPermission/{sid_user}");
            return;
        }
        var tempID = 0;
            tempID = $("#RoleTable").getCell(rowid, "Id");
        if (tempID == 0)
            return;
        $("#role_edit").attr("href", role_edit_url + tempID.toString());
        $("#Permission_role_select").attr("href", "/Permission/Role/roleSelect/" + tempID.toString());
        $("#Permission_role_SelectModule").attr("href", "/Permission/Role/SelectModule/" + tempID.toString() + "");
        $("#Permission_role_LinkUser").attr("href", "/Permission/Role/LinkUser/" + tempID.toString());
        $("#Permission_role_SelectPermission").attr("href", "/Permission/Role/SelectPermission/" + tempID.toString());
        role_jqgrid_lastID = tempID;
    }

    //实现模糊查询
    $().ready(function () {
        $("#txtkeyword_Permission_Role_Index").keyup(
        function () {
            $("#RoleTable tr:gt(0)").hide();
            var $d = $("#RoleTable tr:gt(0)").filter(":contains('" + $.trim($("#txtkeyword_Permission_Role_Index").val()) + "')");
            $d.show();
        }
      )
    })      
</script>
<div id="page_Permission_Role_Index" class="page">
    @*顶部按钮*@
    <div class="panelBar">
        <ul class="toolBar">
            <li class="nobg">关键字：<input type="text" id="txtkeyword_Permission_Role_Index" />
            </li>
            @*            <li class="line">line</li>*@ @*            <li><a class="add" @Html.Raw(ViewBag.Add ? "" : "style=\"display:none;\"") href="/Permission/Role/AddRole" rel="Role_Add" target="dialog"
                title="添加角色" mask="true"><span>添加</span></a></li>
            <li><a class="delete" @Html.Raw(ViewBag.Edit ? "" : "style=\"display:none;\"") href="javascript:void(0)" id="Permission_Role_delete" onclick="javascript:return Role_Delete()">
                <span>删除</span></a></li>
            <li><a class="edit" id="role_edit" @Html.Raw(ViewBag.Del ? "" : "style=\"display:none;\"") href="/Permission/Role/roleEdit/{sid_user}" target="dialog"
                mask="true" title="编辑角色"><span>修改</span></a></li>
            <li><a class="edit" id="Permission_role_select" @Html.Raw(ViewBag.Del ? "" : "style=\"display:none;\"") href="/Permission/Role/roleSelect/{sid_user}" target="dialog"
                mask="true" title="角色授权范围" width="900" height="700"><span>角色授权范围</span></a></li>*@
            @*            <li><a class="edit" id="Permission_role_LinkUser" @Html.Raw(ViewBag.Del ? "" : "style=\"display:none;\"") href="/Permission/Role/LinkUser/{sid_user}" target="dialog"
                mask="true" title="关联用户" width="800" height="600"><span>关联用户</span></a></li>*@
            @*            <li><a class="edit" id="Permission_role_SelectModule" @Html.Raw(ViewBag.Del ? "" : "style=\"display:none;\"") href="/Permission/Role/SelectModule/{sid_user}" target="dialog"
                mask="true" title="分配菜单访问权限" width="800" height="600"><span>分配菜单访问权限</span></a></li>*@
            @*            <li><a class="edit" id="Permission_role_SelectPermission" @Html.Raw(ViewBag.Del ? "" : "style=\"display:none;\"") href="/Permission/Role/SelectPermission/{sid_user}" target="dialog"
                mask="true" title="关联操作权限" width="800" height="600"><span>关联操作权限</span></a></li>*@
            <li>@Html.PermissionButton("Permission.Role.AddRole", "", "add", "/Permission/Role/AddRole", "Role_Add", "dialog", "添加角色", "true", "400", "280", "添加")</li>
            <li>@Html.PermissionButton("Permission.Role.Delete", "Permission_Role_delete", "delete", "javascript:void(0)", "", "", "", "", "删除")</li>
            <li>@Html.PermissionButton("Permission.Role.roleEdit", "role_edit", "edit", "/Permission/Role/roleEdit/{sid_user}", "", "dialog", "编辑角色", "true", "400", "280", "编辑")</li>
            <li class="line"></li>
            <li>@Html.PermissionButton("Permission.Role.roleSelect", "Permission_role_select", "righted", "/Permission/Role/roleSelect/{sid_user}", "", "dialog", "二次授权", "true", "360", "480", "二次授权")</li>
            <li>@Html.PermissionButton("Permission.Role.LinkUser", "Permission_role_LinkUser", "linkuser", "/Permission/Role/LinkUser/{sid_user}", "", "dialog", "关联用户", "true", "360", "480", "关联用户")</li>
            <li class="line"></li>
            <li>@Html.PermissionButton("Permission.Role.SelectModule", "Permission_role_SelectModule", "menuright", "/Permission/Role/SelectModule/{sid_user}", "", "dialog", "菜单权限", "true", "360", "480", "菜单权限")</li>
            <li>@Html.PermissionButton("Permission.Role.SelectPermission", "Permission_role_SelectPermission", "conrtolright", "/Permission/Role/SelectPermission/{sid_user}", "", "dialog", "操作权限", "true", "360", "480", "操作权限")</li>
        </ul>
    </div>
    <div id="mainContent">
        <div class="tableList" layouth="27">
            <table id="RoleTable">
            </table>
        </div>
    </div>
</div>
